package rmmk.algorithms.features.fatures;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import rmmk.algorithms.features.abstraction.AbstractFeatureExtractor;
import rmmk.framework.datasources.Document;

public class NumberExtractor extends AbstractFeatureExtractor {

	private int size = 1;
	
	public NumberExtractor(int size){
		this.size = size;
	}
	
	@Override
	public Double[] doCalculate(Document document) {
		Double[] ret = new Double[size];
		
		Pattern intsOnly = Pattern.compile("\\d+");
		Matcher makeMatch = intsOnly.matcher(document.getTEXT());

		ArrayList<Double> numbers = new ArrayList<>(makeMatch.groupCount());
		
		while (makeMatch.find()) {
		      //System.out.print("Start index: " + matcher.start());
		      //System.out.print(" End index: " + matcher.end() + " ");
		      numbers.add(Double.parseDouble(makeMatch.group()));
		    }
		
		for(int i = 0; i < size; ++i)
		{
			ret[i] = getBiggest(numbers);
		}
		
		return ret;
	}

	private Double getBiggest(ArrayList<Double> numbers) {

		Double biggest = 0.0;
		
		for(Double d : numbers)
			if(d > biggest)
				biggest = d;
		
		return biggest;
	}

	@Override
	public int getFeatureSize() {
		return this.size;
	}

}
